package com.codeoss.framework.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.codeoss.framework.response.FileImportResponse;
import com.codeoss.framework.service.IFileImportService;

@Controller
@RequestMapping("fileimport")
public class FileImportController {
	@Autowired
	private IFileImportService fileImportService;
	
	@RequestMapping(value = "init", method = RequestMethod.GET)
	@ResponseBody
	public FileImportResponse  init(){
		FileImportResponse fileImportResponse=fileImportService.init();
		return fileImportResponse;
	}
	
	@RequestMapping(value = "upload", method = RequestMethod.POST)
	@ResponseBody
	public FileImportResponse upload(@RequestParam("model") String model,@RequestParam("file") MultipartFile file)throws IOException{
		FileImportResponse fileImportResponse=fileImportService.upload(model,file.getInputStream(),file.getOriginalFilename());
		return fileImportResponse;
	}
}
